package com.capa.utils

import org.json.JSONObject
import org.json.JSONTokener

/**
 * Json结果解析类
 */
open class JsonParser{
    companion object {
        fun parseIatResult(json: String?): String {
            val ret = StringBuffer()
            try {
                val tokener = JSONTokener(json)
                val joResult = JSONObject(tokener)

                val words = joResult.getJSONArray("ws")
                for (i in 0 until words.length()) {
                    // 转写结果词，默认使用第一个结果
                    val items = words.getJSONObject(i).getJSONArray("cw")
                    val obj = items.getJSONObject(0)
                    ret.append(obj.getString("w"))
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
            return ret.toString()
        }
    }
}